/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pipeline;

import baseObjects.Symbol;

/**
 *
 * @author avishai
 */
public class KeyboardKey {

    private Character reg = null;
    private Character shift = null;
    private Character alt = null;
    private Character ctrl = null;

    public KeyboardKey() {
    }

    public KeyboardKey(Symbol sym) {
        this.reg = sym.getRegular();
        this.shift = sym.getShift();
        this.alt = sym.getAlt();
        this.ctrl = sym.getCtrl();
    }

    public KeyboardKey(KeyboardKey other) {
        this.reg = other.reg;
        this.shift = other.shift;
        this.alt = other.alt;
        this.ctrl = other.ctrl;
    }

    public boolean addValue(Character c) {
        if (this.reg != null) {
            this.reg = c;
            return true;
        } else if (this.shift != null) {
            this.shift = c;
            return true;
        } else if (this.alt != null) {
            this.alt = c;
            return true;
        } else if (this.ctrl != null) {
            this.ctrl = c;
            return true;
        }

        return false;
    }

    public void setAlt(Character alt) {
        this.alt = alt;
    }

    public void setCtrl(Character ctrl) {
        this.ctrl = ctrl;
    }

    public void setReg(Character reg) {
        this.reg = reg;
    }

    public void setShift(Character shift) {
        this.shift = shift;
    }

    public Character getAlt() {
        return alt;
    }

    public Character getCtrl() {
        return ctrl;
    }

    public Character getReg() {
        return reg;
    }

    public Character getShift() {
        return shift;
    }

    public Symbol getSymbol(){
        Symbol ans = new Symbol(this.reg, this.shift);
        ans.setAlt(this.alt);
        ans.setCtrl(this.ctrl);
        return ans;
    }

    public boolean hasShift(){
        return shift!=null;
    }
    public boolean hasCtrl(){
        return ctrl != null;
    }
    public boolean hasAlt(){
        return alt != null;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final KeyboardKey other = (KeyboardKey) obj;
        if (this.reg != other.reg && (this.reg == null || !this.reg.equals(other.reg))) {
            return false;
        }
        if (this.shift != other.shift && (this.shift == null || !this.shift.equals(other.shift))) {
            return false;
        }
        if (this.alt != other.alt && (this.alt == null || !this.alt.equals(other.alt))) {
            return false;
        }
        if (this.ctrl != other.ctrl && (this.ctrl == null || !this.ctrl.equals(other.ctrl))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        //sb.append("[r,s,a,c]");
//        sb.append(System.getProperty("line.separator"));
        sb.append("[");
        sb.append(this.reg);
        sb.append(",");
        sb.append(this.shift);
        sb.append(",");
        sb.append(this.alt);
        sb.append(",");
        sb.append(this.ctrl);
        sb.append("]");
        return sb.toString();
    }
}
